package com.mactivity.activities;

import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.mactivity.helper.Constants;
import com.mactivity.helper.SharedPreferenceHelper;

public class ProfileActivity extends Activity implements OnClickListener{
	TextView textFullName;
	TextView textEmailId;

	Button buttonLogout;

	Map<String, String> userDetails = null;
	
	SharedPreferenceHelper sharedPref = null;

	/**
	 * This method is called on the activity creation. It locates the screen
	 * elements and binds the elements to the functions that occur.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.profile);

		textEmailId = (TextView) findViewById(R.id.textProfileEmail);
		textFullName = (TextView) findViewById(R.id.textProfileName);

		buttonLogout = (Button) findViewById(R.id.buttonProfileLogout);
		
		// On click of register check the values entered and register the user
		buttonLogout.setOnClickListener(this);

		// Fetch the details from Shared Preferences
		sharedPref = new SharedPreferenceHelper(this);
		userDetails = sharedPref.getUserInformation();

		// Display the information on the screen
		textEmailId.setText(userDetails.get(Constants.USER_EMAIL_ID));
		textFullName.setText(userDetails.get(Constants.USER_NAME));

		

	}
	
	/**
	 * 
	 */
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.buttonProfileLogout:

			SharedPreferences settings = sharedPref.getSharedPreferenceSetting();
		    SharedPreferences.Editor editor = settings.edit();
		    editor.putBoolean("loggedIn", false);
		    // Commit the edits!
		    editor.commit();
		    Intent myIntent = new Intent();
    		myIntent = new Intent(ProfileActivity.this, LoginActivity.class);
    		startActivity(myIntent);
    		finish();
		}

	}

	
	
	/**
	 * Override the Back button operation to navigate to the Login page.
	 */
	@Override
	public void onBackPressed() {
		Intent myIntent = new Intent(ProfileActivity.this, HomeActivity.class);
		ProfileActivity.this.startActivity(myIntent);
		finish();
	}

}
